<?php
App::uses('AppController', 'Controller');
/**
 * Norecibos Controller
 *
 * @property Norecibo $Norecibo
 * @property PaginatorComponent $Paginator
 */
class NorecibosController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');
        public $uses = array('Norecibo');
        public $layout = 'sib';

/**
 * index method
 *
 * @return void
 */
	public function index() 
        {
        $norecibos = $this->Norecibo->find('all', array(
            'recursive' => -1,
            'order' => 'Norecibo.id DESC',));
        $this->set(compact('norecibos'));
        //debug($colegiado);die;
    }

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Norecibo->exists($id)) {
			throw new NotFoundException(__('Invalid norecibo'));
		}
		$options = array('conditions' => array('Norecibo.' . $this->Norecibo->primaryKey => $id));
		$this->set('norecibo', $this->Norecibo->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add()
    {
        if (!empty($this->request->data)) {
            $this->Norecibo->create();
            //debug($this->request->data);die;
            if ($this->Norecibo->save($this->request->data)) {
                $this->Session->setFlash('Numero de Recibo registrado con exito', 'msgbueno');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('No se pudo registrar el Numero de Recibo','msgerror');
            }
        }
    }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null)
    {
        $this->Norecibo->id = $id;
        if (!$id) {
            $this->Session->setFlash('No existe el Numero de Recibo');
            $this->redirect(array('action' => 'index'), null, true);
        }
        if (empty($this->request->data)) {
            $this->request->data = $this->Norecibo->read();
        } else {
            if ($this->Norecibo->save($this->request->data)) {
                $this->Session->setFlash('Los datos fueron modificados', 'msgbueno');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('no se pudo modificar!!','msgerror');
            }
        }
    }

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null)
    {
        $this->Norecibo->id = $id;
        $this->request->data = $this->Norecibo->read();
        if (!$id) {
            $this->Session->setFlash('No existe el Numero de Recibo a Eliminar','msgbueno');
            $this->redirect(array('action' => 'index'));
        } else {
            if ($this->Norecibo->delete($id)) {
                $this->Session->setFlash('Se elimino el Numero de Recibo ' . $this->data['Norecibo']['noinicial'],
                    'msgbueno');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Error al eliminar','msgerror');
            }
        }
    }
}
